﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Entity
{
    /// <summary>
    /// 通用消息序列类
    /// </summary>
    public class VMessage : IEnumerable<string>
    {
        /// <summary>
        /// 是否完成
        /// </summary>
        public bool IsComplete { get; set; }

        /// <summary>
        /// 可以返回一个EntityBase类型的实体
        /// </summary>
        public EntityBase Entity { get; set; }

        /// <summary>
        /// 消息序列
        /// </summary>
        List<string> list = new List<string>();

        Dictionary<string, string> dic = new Dictionary<string, string>();

        /// <summary>
        /// 向序列中添加新的项
        /// </summary>
        /// <param name="item"></param>
        public void AddItem(string item)
        {
            this.list.Add(item);
        }


        /// <summary>
        /// 向序列中添加新的项
        /// </summary>
        /// <param name="index">数值索引</param>
        /// <param name="item"></param>
        public void AddKeyValueItem(string index, string item)
        {
            this.dic.Add(index, item);

        }
        /// <summary>
        /// 键值消息键是否存在
        /// </summary>
        /// <param name="index">键</param>
        /// <returns>是否存在</returns>
        public bool ContainsKey(string index)
        {
            return this.dic.ContainsKey(index);
        }

        /// <summary>
        /// 向序列中追加一个新的序列
        /// </summary>
        /// <param name="itemRange">序列对象</param>
        public void AddItemRange(IEnumerable<string> itemRange)
        {
            this.list.AddRange(itemRange);
        }
        /// <summary>
        /// 消息对象
        /// </summary>
        public Object Object { get; set; }

        /// <summary>
        /// 清空所有现有项
        /// </summary>
        public void Clear()
        {
            this.list.Clear();
        }

        /// <summary>
        /// 索引器
        /// </summary>
        /// <param name="index">索引</param>
        /// <returns>相应值</returns>
        public string this[int index]
        {
            get { return this.list[index]; }

        }

        /// <summary>
        /// 索引器
        /// </summary>
        /// <param name="index">索引</param>
        /// <returns>相应值</returns>
        public string this[string index]
        {
            get
            {
                return this.dic[index];
            }

        }

        #region IEnumerable<string> 成员

        public IEnumerator<string> GetEnumerator()
        {
            return this.list.GetEnumerator();
        }

        #endregion

        #region IEnumerable 成员

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.list.GetEnumerator();
        }

        #endregion
    }
}
